package string;

import javax.jws.soap.SOAPBinding;

public class Test {
    public static void main(String[] args) {
        String str = "hello";
        String str1 = new String("hello");
        System.out.println(str1.length());   //字符串长度
        System.out.println(str1.indexOf('l'));
        System.out.println(str1.indexOf('l', 3));
        System.out.println(str1.lastIndexOf('l'));
        System.out.println(str1.equals(str));
        System.out.println(str == str1);

       String str3 =  str.concat(str1);  //合并字符串
        System.out.println(str3);
        char c = str1.charAt(0);
        System.out.println(c);

        String s1 = String.valueOf(110) + 1;
        System.out.println(s1);

        String str4 = new String("good");
        String str5 = new String("cat");
        String s2 = new String("Cat");
        String s3 = "good";
        String s4 = "good";

        System.out.println(s3 == s4);   //true
        System.out.println(s3.equals(str4));  //true
        System.out.println(str5.equalsIgnoreCase(s2));   //不区分大小写 来比较相等   true
        System.out.println(str4 == s4);  //false

        System.out.println("===========");
        //去除字符串左右两边的空格
        String ret = new String("     P Y T H O N     ");
        System.out.println(ret);

        String ret1 = ret.trim();
        System.out.println(ret1);
        //去除字符串中的所有空格
        String ret2 = ret.replace(" ","");   //替换和被替换的类型要一致
        System.out.println( "替换所有的空格之后的字符串: "+ ret2);

        //字符串的大小写转换
        String tmp = "Hello World";
        //全部转为大写
        String tmp1 = tmp.toUpperCase();
        System.out.println(tmp1);
        //全部转为小写
        String tmp2 = tmp.toLowerCase();
        System.out.println(tmp2);
        System.out.println("^^^^^^^^");
        //切割和截取
        String string = "爱情-亲情-友情";
        //根据-来截取  出字符串   用字符串数组接收
        String[] strings = string.split("-");
        for (int i = 0; i < strings.length; i++) {
            System.out.print(strings[i] + " ");
        }
        System.out.println();
        //字符串截取
        String s8 = "substring123";
        String str8 = s8.substring(3);  //这个是从第三个位置开始截取
        System.out.println(str8);
        //截取出123
        String t = s8.substring(9,s8.length());
        System.out.println(t);
    }
}
